<template>
	<view class="page-wrap" :data-theme="theme" :class="theme" :style="globalColor.style">
		<HeadCustom :isSpace="false" :isBg="false" :isAppBtn="false" :isHome="!isApp"></HeadCustom>
		<view class="wrap">
			<view class="bg-head">
				<view :style="{ height: statusBarHeight + 'px' }"></view>
				<view class="spaceHead"></view>
				<view class="management-hd">
					<view class="userInfo fboxRow" @click="goCard()">
						<image class="avatar" :src="detail.avatar" mode="aspectFill"></image>
						<view class="fboxCol flex1 Xcenter">
							<view class="name lh54 font38">{{ detail.realName }}</view>
							<view class="completion lh40 color-ACB4C7 mt12 font28">资料完成度{{ detail.resumeCompletePercent }}%</view>
						</view>
						<!-- <view class="btn color-E8CDA7 fboxRow Ycenter Xcenter border-radius12 font28" @click="goView">预览简历</view> -->
					</view>
					<view class="info-group fboxRow Ycenter mt48">
						<view class="fboxCol Ycenter Xcenter flex1 action-item" v-for="(item, index) in infoList" :key="index" @click="goPage(item)">
							<!-- <view class="icon"><image src="https://ebc-prod.cdn.benwunet.com/uni-static/workplace/vita.png"></image></view> -->
							<view class="num font38 fwb color-E8CDA7">{{ detail[item.key] || 0 }}</view>
							<view class="tit font26 mt30 color-ACB4C7">{{ item.tit }}</view>
						</view>
					</view>
				</view>
				<view class="sign fboxRow Ycenter">
					<view class="fboxCol Xcenter flex1">
						<view class="tit font38">我要招聘</view>
						<view class="sub mt16 font24 ">众多招聘者的选择</view>
					</view>
					<view class="btn fboxRow Ycenter Xcenter bg-linear color-141720" @click="$pageTo('/recruit/user/enterprise')">切换到企业</view>
				</view>
			</view>
			<view class="nav-list fboxCol border-radius12">
				<template v-for="(item, index) in navList">
					<view :key="index" @click="goPage(item)">
						<view class="fboxRow Ycenter nav-item">
							<image class="icon" :src="item.icon"></image>
							<view class="tit flex1 font32 ">{{ item.tit }}</view>
							<text class="bwfont bw-arrow-right font24" style="color: #D7DCE1;"></text>
						</view>
						<view class="line"></view>
					</view>
				</template>
			</view>
			<view class="fboxRow Ycenter Xcenter fixed-about">
				<!--  @click="$pageTo('/about/index?settingCode=HUMAN_RESOURCES_LICENSE')" -->
				<text class="font24 color-6B707C">(渝)人服证字[2023]号 第4000001313号</text>
			</view>
		</view>
		<view class="changePage">
			<view class="bottomDetail fboxRow">
				<view class="btn flex1  zwmsg font30 fboxRow Xcenter Ycenter" @click="goPost">
					<text class="bwfont bw-zhiwei"></text>
					<text>职位信息</text>
				</view>
				<view class="btn flex1 active bg-linear jlmy font30 fboxRow Xcenter Ycenter">
					<text class="bwfont bw-wode"></text>
					<text>我的简历</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { resumeInfo, resumeDataCount, currentMember } from '@/api/recruit.js';
import { getRequest } from '@/static/js/common.js';
import { utf8to16, base64decode } from '@/static/js/Base64.js';
export default {
	data() {
		return {
			theme: getApp().globalData.appTheme,
			globalColor: getApp().globalData.globalColor,
			infoList: [
				{ key: 'deliverCount', num: 12, tit: '投过的职位', path: '/recruit/user/deliverPage' },
				{ key: 'interviewCount', num: 12, tit: '收到的面试', path: '/recruit/user/myInterview' },
				{ key: 'collectJobCount', num: 12, tit: '收藏的职位', path: '/recruit/user/collectPage' }
			],
			navList: [
				{ icon: 'https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/icon-1.png', tit: '我的简历', path: '/recruit/user/vita' },
				// { icon: 'https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/icon-3.png', tit: '语音简历', path: '/recruit/user/vita-audio' },
				// { icon: 'https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/icon-4.png', tit: '视频简历', path: '/recruit/user/vita-video' },
				{ icon: 'https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/icon-2.png', tit: '附件简历', path: '/recruit/user/vita-file' },
				{ icon: 'https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/icon-3.png', tit: '求职意向', path: '/recruit/user/vita-expect' },
				{ icon: 'https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/icon-4.png', tit: '简历设置', path: '/recruit/user/vitaSet' }
			],
			isApp: false,
			detail: {},
			statusBarHeight: 0,
			isChange: false // 是否从数字职场首页跳转过来的，true 点击切换职位信息时用uniback返回，false uninavg跳转到职位信息
		};
	},
	onLoad(option) {
		if (option && option.benwu) {
			const benwu = utf8to16(base64decode(option.benwu));
			const token = {
				access_token: getRequest(benwu, 'token'),
				userId: getRequest(benwu, 'userId'),
				statusBarHeight: getRequest(benwu, 'statusBarHeight')
			};
			getApp().globalData.userId = token.userId;
			getApp().globalData.statusBarHeight = token.statusBarHeight;
			uni.setStorageSync('bw_params', JSON.stringify(token));
		}
		if (option && option.isApp) {
			this.isApp = option.isApp == 1 ? true : false;
		}
		if (option && option.isChange) {
			this.isChange = true
		}
		const { bw_params } = getApp().getBWData(['bw_params']);
		this.statusBarHeight = getApp().globalData.statusBarHeight || bw_params.statusBarHeight;
		if (!getApp().globalData.statusBarHeight) {
			const sys = uni.getSystemInfoSync();
			this.statusBarHeight = sys.statusBarHeight;
		}
		// #ifdef MP
		// 根据胶囊按钮距离， 设置导航高度
		const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
		this.statusBarHeight = menuButtonInfo.top;
		// #endif
	},
	onShow() {
		this.getInit();
	},
	methods: {
		// 跳转职位
		goPost() {
			console.log('this.isChange',this.isChange)
			if(this.isChange){
				uni.navigateBack()
			}else{
				this.$pageTo('/recruit/user/index?isChange=1');
			}
		},
		goCard() {
			const { bw_link } = getApp().getBWData(['bw_link']);
			if (bw_link.isApp != 1) {
				this.$pageTo('/CardDetail', { id: this.detail.memberId });
			} else {
				const data = {
					type: 'card',
					memberId: this.detail.memberId
				};
				this.$bridge.callHandler('recruitHandler', data, () => {
					console.log('recruitHandler', '返回');
				});
			}
		},
		goView() {
			if (this.fromData.id) {
				this.$pageTo('/recruit/user/detail?pageType=0&id=' + this.fromData.id);
			} else {
				uni.showToast({
					icon: 'none',
					title: '请完善你的简历'
				});
			}
		},
		// 用户数据统计
		getCount(id) {
			resumeDataCount({
				memberType: 1,
				countId: id
			}).then(res => {
				this.detail = {
					...this.detail,
					...res.data
				};
			});
		},
		getInit() {
			resumeInfo().then(res => {
				if (res.data) {
					getApp().globalData.vitaTemp = res.data;
					this.detail = res.data;
					this.getCount(res.data.memberId);
				} else {
					this.getInfo();
				}
			});
		},
		// 当前用户没有填写简历时，取用户信息基础数据
		getInfo() {
			currentMember().then(res => {
				if (res.data) {
					getApp().globalData.vitaTemp = res.data;
					this.detail = res.data;
				}
			});
		},
		goPage(e) {
			if (e.path == 'copy') {
				uni.setClipboardData({
					data: location.href,
					success: function() {
						console.log('success');
					}
				});
			} else {
				this.$pageTo(e.path);
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.changePage {
	display: flex;
	justify-content: center;
	width: 100%;
	height: 130rpx;
	position: fixed;
	bottom: 0rpx;
	.bottomDetail {
		height: 88rpx;
		width: 670rpx;
		border-radius: 12rpx;
		background: #ffffff;
		box-shadow: 0 4rpx 10rpx rgba(0,0,0,.2);
		overflow: hidden;
		.bwfont {
			margin-right: 10rpx;
			font-size: 34rpx;
		}
		.btn {
			color: var(--titleFontColor);
		}
		.active{
			color: var(--contentBgImageTitleColor);
		}
	}
}
.page-wrap {
	min-height: 100vh;
}
// .wrap {
// 	padding: 112rpx 24rpx 24rpx;
// 	background: url('https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/bg2.png') no-repeat top center/contain;
// }

[data-theme='night-theme'] {
	.wrap{padding:24rpx 24rpx 24rpx;background: url('https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/bg3.png') no-repeat top center/contain;}
}
[data-theme='lightBlue-theme'] {
	.bg-head{padding: 24rpx 24rpx 0;background: linear-gradient(180deg, var(--navViewStartColor) 0%, var(--navViewCenterColor) 32%, rgba(255,255,255,0) 100%);}
}
.management-hd {
	padding: 0 0 24rpx;
}
.management-hd .avatar {
	margin: 0 30rpx 0 0;
	width: 120rpx;
	height: 120rpx;
	overflow: hidden;
	border-radius: 50%;
}
.management-hd .btn {
	width: 168rpx;
	height: 64rpx;
	background: rgba(255, 217, 181, 0.1);
}
.lh54 {
	line-height: 54rpx;
}
.info-group {
	padding: 0 0 34rpx;
}
// .action-item {
// 	position: relative;
// }
// .action-item::before {
// 	content: '';
// 	position: absolute;
// 	left: 0;
// 	top: 50%;
// 	margin-top: -24rpx;
// 	height: 48rpx;
// 	width: 1rpx;
// 	background-color: rgba(255, 255, 255, 0.08);
// }
// .action-item:first-child::before {
// 	display: none;
// }
.sign {
	padding: 0 30rpx;
	height: 132rpx;
	background: url('https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/bg.png') top center/cover;
	border-radius: 12rpx;
	overflow: hidden;
}

[data-theme='night-theme'] {
	.sign{background: url('https://ebc-prod.cdn.benwunet.com/uni-static/img3.3.0/recruit/bg.png') top center/cover;}
}
[data-theme='lightBlue-theme'] {
	.sign{background: url('https://ebc-prod.cdn.benwunet.com/uni-static/img3.5.0/recruit/bg-min.png') top center/cover;}
}
.sign .btn {
	width: 172rpx;
	height: 48rpx;
	border-radius: 8rpx;
}

.nav-list {
	margin: 40rpx 24rpx 0;
	padding: 0 24rpx;
	background-color: var(--viewBgColor);
}
.nav-list .icon {
	width: 40rpx;
	height: 40rpx;
	margin-right: 24rpx;
}
.nav-item {
	padding: 30rpx 0;
	height: 110rpx;
}
.line {
	margin-top: 4rpx;
	height: 1rpx;
	background-color: var(--viewDivisionColor);
}

.fixed-about {
	position: absolute;
	bottom: 66rpx;
	left: 0;
	right: 0;
}
</style>
